<?php

/*
 * EachGo电商网站 新媒体
 * www.eachgo.cn
 */

namespace Home\Model;

/**
 * AgentInfo
 * 请输入描述
 * @author Moon
 */
use Think\Model;

class AgentInfoModel extends Model {
    /*
     * 增加一条记录
     */

    public function addAgentInfo($obj) {
        //$data = D('AgentInfo');
        $res = $this->add($obj);
        return $res;
    }

    /*
     * 删除一条记录
     */

    public function deleteAgentInfo($obj) {
        //$data = D('AgentInfo');
        $res = $this->where('ID = "' . $obj['ID'] . '"')->delete($obj);
        return $res;
    }

    /*
     * 更新一条记录
     */

    public function updateAgentInfo($obj) {
        //$data = D('AgentInfo');
        $res = $this->where('ID = "' . $obj['ID'] . '"')->save($obj);
        return $res;
    }

    /*
     * 查询一条记录ID
     */

    public function selectAgentInfoById($obj) {
        //$data = D('AgentInfo');
        $res = $this->where('ID = "' . $obj['ID'] . '"')->select();
        return $res;
    }

    /*
     * 查询一条记录BySchoolId
     */

    public function selectAgentInfoBySchoolId($obj) {
        //$data = D('AgentInfo');
        $res = $this->where('school_ID = "' . $obj['school_ID'] . '"')->select();
        return $res;
    }

    /*
     * 查询一条记录ByName
     */

    public function selectAgentInfoByName($obj) {
        //$data = D('AgentInfo');
        $res = $this->where('name like "%' . $obj['name'] . '%"')->select();
        return $res;
    }

    /*
     * 查询所有记录
     */

    public function selectAgentInfoByDefault($obj) {
        //$data = D('AgentInfo');
        $res = $this->select();
        return $res;
    }

    /**
     * 用户登录验证
     */
    public function checkLogin($obj) {
        $res = -1;

        $sql = "SELECT * FROM t_agent_info WHERE phone_number='" . $obj['phone_number'] . "  AND is_Agent=1  ";

        $data = $this->execute($sql);

        if (empty($data)) {
            return $res;
        }

        if ($data['password'] != $obj['password']) {
            $res = -2;
            return $res;
        }

        $res = 1;
        return $res;
    }

    /*
     * 是否为Agent
     */

    public function selectIsAgent($obj) {
        $data = $this->where('ID = "' . $obj['ID'] . '"')->select();
        return $data['is_Agent'];
    }

    /*
     * 更改密码
     */

    public function updatePassword($obj) {
        $this->where('ID = "' . $obj['ID'] . '"')->save($obj);
    }

}
